import { ref,reactive} from 'vue'
export const useInitMapNodes = function (nodes)  {
  let len =  nodes.length
  console.log("🚀 ~ useInitMapNodes ~ len:", len)
  if(len <= 0) return {nodes: []}
  let map = new Map()
  for(let index = len - 1; index >= 0; index--){
    let item = nodes[index]
    let row = item['row']
    if(map.has(row)){
      let rowSubNodes = map.get(row)
      map.set(row, [...rowSubNodes, item])
    }else{
      map.set(row, [item])
    }
  }
  console.log(map)
  let list = []
  map.forEach((value,key) => {
    let children = value.sort((a,b)=> a.column - b.column)
    list.unshift({
      row: key,
      children
    })
  })
  return reactive({
    nodes:list
  })
}